package com.example.usermanagement.liuka.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.usermanagement.exception.ObjectNotException;
import com.example.usermanagement.exception.ServerErrorException;
import com.example.usermanagement.liuka.service.FlowMessageService;
import com.example.usermanagement.liuka.service.FlowPackageUserService;
import com.example.usermanagement.vo.FlowMessageVO;
import com.example.usermanagement.vo.FlowPackageInfoVO;
import lombok.AllArgsConstructor;
import lombok.NonNull;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;


/**
 * 购买用户记录
 */
@AllArgsConstructor
@RestController
@RequestMapping("/flow-package-user")
@Validated
public class FlowPackageUserController {


    private final FlowPackageUserService flowPackageUserService;


    /**
     * 用户购买套餐包
     * @param packageId 套餐包id
     * @param phone  手机号
     * @param flowUserId  购买用户id
    **/
    @PostMapping("/shop")
    public void shopPackage(@NotNull(message = " 套餐包id不能为空")Long packageId,
                            @NotNull(message = "购买用户手机号不能为空")String phone,
                            Long flowUserId) throws ServerErrorException {
        flowPackageUserService.shopPackage(packageId,flowUserId,phone);
    }



    /**
     *   购买记录查询
     * @param page 第几页 默认1
     * @param pageSize 每页条数 默认20
     * @param name 姓名
     * @param phone 电话
     * @param packageName 套餐包名
     * @return
     */
    @GetMapping("/page")
    public IPage<FlowPackageInfoVO> getFlowPackageUser(@RequestParam(defaultValue = "1")Long page,
                                                       @RequestParam(defaultValue = "20")Long pageSize,
                                                       String name,String phone,String packageName){
        return flowPackageUserService.selectByPage(new Page(page,pageSize),name,packageName,phone);
    }


    /**
     * 关闭流量卡
     * @param flowPackageUserId 订购信息id
     *
     */
    @PutMapping("/stop")
    public void stopPackage(@NotNull(message = "flowPackageUserId")Long flowPackageUserId) throws ObjectNotException {


        flowPackageUserService.stopFlowPackageUser(flowPackageUserId);
    }

    /**
     * 通知消息列表
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/message/list")
    public IPage<FlowMessageVO> getPage(@RequestParam(defaultValue = "1")Long page,
                                        @RequestParam(defaultValue = "20")Long pageSize){
        return flowPackageUserService.getMessage().selectByPage(new Page(page,pageSize));
    }

}
